/*---------------------------
        student_system.c
---------------------------*/
#include "student_system.h"
#include <stdlib.h>
#include <stdio.h>

#define MAX_STUDENTS 50
static Student students[MAX_STUDENTS];
static int student_count = 0;

void student_system_init(void) 
{
    // 初始化UI组件
    ui_init();
}

void add_student(int id, const char* name, float score) 
{
    if(student_count < MAX_STUDENTS) {
        students[student_count].id = id;
        snprintf(students[student_count].name, 32, "%s", name);
        students[student_count].score = score;
        student_count++;
    }
}

void display_all_students(void) 
{
    // 先清空旧数据
    ui_clear_list();
    
    // 遍历并显示
    for(int i = 0; i < student_count; i++) {
        char buffer[64];
        snprintf(buffer, sizeof(buffer), "%d. %s (%.1f)", 
                students[i].id, students[i].name, students[i].score);
        ui_display_student(buffer);
    }
}